﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SaunaServer.Controller.Communication;
using SaunaServer.Model.Network;
using SaunaServer.Model.Database;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using SaunaServer.View;

namespace SaunaServerUnitTest
{
    [TestClass]
    public class UnitTestDBDaoGateway
    {
        private IDBFactory dbFactory;
        private IDBDaoGateway dbDao = null;
        private const string DATABASE_DAO = "DatabaseDAO";
        NetworkSetting networkSetting = null;
        private string CONFIG_DIR_FILE_NAME = @"G:\JCU_Y2_SP2\Software Engineering - CP2013\SourceCode\CommunicationServer\CommunicationServer\bin\Debug\SaunaConfig.ini";

        [TestMethod]
        public void TestReadDBBaseSetting()
        {
            // Create Communication Manager
            CommunicationManager communicationManager = new CommunicationManager(new CommunicationServerForm());

            // Read Sauna configuration file and create network setting
            networkSetting = communicationManager.ReadConfigFileFromDirectory(CONFIG_DIR_FILE_NAME);
            Assert.IsNotNull(networkSetting);
        }

        [TestMethod]
        public void TestCreateDBDaoConnection()
        {
            TestReadDBBaseSetting();

            // Create Database DAO
            dbFactory = new DBFactoryImplementation();
            dbDao = dbFactory.Make(DATABASE_DAO, networkSetting);
            Assert.IsNotNull(dbDao);
        }

        [TestMethod]
        public void TestAuthenticateUserDeny()
        {
            TestCreateDBDaoConnection();

            string userFullName;
            Assert.IsFalse(dbDao.AuthenticateUser("TestUserDummy", "pass", out userFullName));
        }


        [TestMethod]
        public void TestAuthenticateUserAccept()
        {
            TestCreateDBDaoConnection();

            string userFullName;
            Assert.IsTrue(dbDao.AuthenticateUser("billfred", "pass", out userFullName));
        }
    }
}

